<?php
namespace app\admin\validate;
use think\Validate;

class Tool extends Validate
{
    protected $rule = [
        'icon'      =>  'require',
        'catid'     =>  'require|number',
        'name'      =>  'require',
        'path'      =>  'require',
        'desc'      =>  'require',
        'toolid'    =>  'require|number',
        'method'    =>  'require|in:statusButton,visibleButton,editInfo,sortTool',
        'status'    =>  'require|in:1,2',
        'visible'   =>  'require|in:1,2',
        'old'       =>  'require|number',
        'new'       =>  'require|number',
        'tags'      =>  'require|checkTags',
    ];

    protected $message = [
        'icon.require'  => '图标不能为空!',
        'catid.require' => '分类ID不能为空!',
        'catid.number'  => '分类ID错误!',
        'name.require'  => '名称不能为空!',
        'path.require'  => '路径不能为空!',
        'desc.require'  => '描述不能为空!',
        'toolid.require'=> '工具ID不能为空!',
        'toolid.number' => '工具ID错误!',
        'old.require'   => '原始位置参数不能为空!',
        'old.number'    => '原始位置参数错误!',
        'new.require'   => '移动位置参数不能为空!',
        'new.number'    => '移动位置参数错误!',
        'tags.require'  => '标签参数不能为空!',
    ];

    protected $scene = [
        'create'    =>  ['icon','catid','name','path','desc','tags'],
        'delete'    =>  ['toolid'],
        'editMethod'=>  ['method','toolid'],
        'statusButton'  =>  ['status'],
        'visibleButton' =>  ['visible'],
        'editInfo'  =>  ['icon','catid','name','path','desc','tags'],
        'sortTool'  =>  ['old','new'],
    ];
    
    /**
     * 自定义tags验证规则
     */
    protected function checkTags($value)
    {
        if(is_array(explode(',',$value))){
            return true;
        }
        return '标签参数格式错误!';
    }
}